/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entities;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 *
 * @author anhvh_b00319
 */
@Entity
@Table(name = "Client")
@NamedQueries({
    @NamedQuery(name = "Client.findAll", query = "SELECT c FROM Client c"),
    @NamedQuery(name = "Client.findByClientID", query = "SELECT c FROM Client c WHERE c.clientID = :clientID"),
    @NamedQuery(name = "Client.findByClientFullName", query = "SELECT c FROM Client c WHERE c.clientFullName = :clientFullName"),
    @NamedQuery(name = "Client.findByClientAge", query = "SELECT c FROM Client c WHERE c.clientAge = :clientAge"),
    @NamedQuery(name = "Client.findByClientGender", query = "SELECT c FROM Client c WHERE c.clientGender = :clientGender"),
    @NamedQuery(name = "Client.findByClientAddress", query = "SELECT c FROM Client c WHERE c.clientAddress = :clientAddress"),
    @NamedQuery(name = "Client.findByClientPhone", query = "SELECT c FROM Client c WHERE c.clientPhone = :clientPhone"),
    @NamedQuery(name = "Client.findByClientEmail", query = "SELECT c FROM Client c WHERE c.clientEmail = :clientEmail")})
public class Client implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "Client_ID")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer clientID;
    @Basic(optional = false)
    @Column(name = "Client_FullName")
    private String clientFullName;
    @Basic(optional = false)
    @Column(name = "Client_Age")
    private int clientAge;
    @Basic(optional = false)
    @Column(name = "Client_Gender")
    private boolean clientGender;
    @Transient
    private String gender;
    @Basic(optional = false)
    @Column(name = "Client_Address")
    private String clientAddress;
    @Basic(optional = false)
    @Column(name = "Client_Phone")
    private String clientPhone;
    @Basic(optional = false)
    @Column(name = "Client_Email")
    private String clientEmail;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "client")
    private List<Enrollment> enrollmentList;

    public Client() {
        clientGender = true;
        clientAge = 0;
        enrollmentList = new ArrayList<Enrollment>();
    }

    public Client(Integer clientID) {
        this.clientID = clientID;
    }

    public Client(Integer clientID, String clientFullName, int clientAge, boolean clientGender, String clientAddress, String clientPhone, String clientEmail) {
        this.clientID = clientID;
        this.clientFullName = clientFullName;
        this.clientAge = clientAge;
        this.clientGender = clientGender;
        this.clientAddress = clientAddress;
        this.clientPhone = clientPhone;
        this.clientEmail = clientEmail;
    }

    public Integer getClientID() {
        return clientID;
    }

    public void setClientID(Integer clientID) {
        Integer oldClientID = this.clientID;
        this.clientID = clientID;
        changeSupport.firePropertyChange("clientID", oldClientID, clientID);
    }

    public String getClientFullName() {
        return clientFullName;
    }

    public void setClientFullName(String clientFullName) {
        String oldClientFullName = this.clientFullName;
        this.clientFullName = clientFullName;
        changeSupport.firePropertyChange("clientFullName", oldClientFullName, clientFullName);
    }

    public int getClientAge() {
        return clientAge;
    }

    public void setClientAge(int clientAge) {
        int oldClientAge = this.clientAge;
        this.clientAge = clientAge;
        changeSupport.firePropertyChange("clientAge", oldClientAge, clientAge);
    }

    public boolean getClientGender() {
        return clientGender;
    }

    public void setClientGender(boolean clientGender) {
        boolean oldClientGender = this.clientGender;
        this.clientGender = clientGender;
        changeSupport.firePropertyChange("clientGender", oldClientGender, clientGender);
    }

    public String getGender() {
        if (clientGender) {
            gender = "Male";
        } else {
            gender = "Female";
        }
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getClientAddress() {
        return clientAddress;
    }

    public void setClientAddress(String clientAddress) {
        String oldClientAddress = this.clientAddress;
        this.clientAddress = clientAddress;
        changeSupport.firePropertyChange("clientAddress", oldClientAddress, clientAddress);
    }

    public String getClientPhone() {
        return clientPhone;
    }

    public void setClientPhone(String clientPhone) {
        String oldClientPhone = this.clientPhone;
        this.clientPhone = clientPhone;
        changeSupport.firePropertyChange("clientPhone", oldClientPhone, clientPhone);
    }

    public String getClientEmail() {
        return clientEmail;
    }

    public void setClientEmail(String clientEmail) {
        String oldClientEmail = this.clientEmail;
        this.clientEmail = clientEmail;
        changeSupport.firePropertyChange("clientEmail", oldClientEmail, clientEmail);
    }

    public List<Enrollment> getEnrollmentList() {
        return enrollmentList;
    }

    public void setEnrollmentList(List<Enrollment> enrollmentList) {
        this.enrollmentList = enrollmentList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (clientID != null ? clientID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Client)) {
            return false;
        }
        Client other = (Client) object;
        if ((this.clientID == null && other.clientID != null) || (this.clientID != null && !this.clientID.equals(other.clientID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return clientFullName;
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
}
